package com.me.batm.ai;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import com.badlogic.gdx.math.Vector2;
import com.me.batm.Utils;

public class TargetAIService {

	public static Vector2 selectNextWaypoint(boolean walkMap[][],int x,int y,int preX,int preY,int playerX,int playerY){
		List<Vector2> vc = new LinkedList<Vector2>();
		int xx,yy;
		for(int i=-1;i<=1;i++){
			for(int j=-1;j<=1;j++){
				if((i == 0) == (j == 0))
					continue;

				yy = y + i;
				xx = x + j;

				if(yy < 0 || xx < 0 || yy >= Utils.layerHeight || xx >= Utils.layerWidth)
					continue;

				if(yy == preY && xx == preX)
					continue;

				if(yy == playerY && xx == playerX)
					continue;
				
				if(walkMap[yy][xx] == false)continue;

				vc.add(new Vector2(xx, yy));
			}
		}
		if(vc.isEmpty())return null;
		Collections.shuffle(vc);
		return vc.iterator().next();
	}
}
